package cn.caixiong.basic.utils;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "信息对象", description = "信息对象参数")
public class JsonResult {
    @ApiModelProperty(value = "true:成功 , false:失败")
    private Boolean session = true;
    @ApiModelProperty(value = "提示信息")
    private String message = "ojbk";
    @ApiModelProperty(value = "数据载体")
    private Object data;
    @ApiModelProperty(value = "状态码")
    private String code = PetConstant.CAI_SUCCESS;


    /**
     * 返回成功,不携带数据给前端
     */
    public static JsonResult createSuccess() {
        return new JsonResult();
    }

    /**
     * 返回成功,要携带数据给前端
     */
    public static JsonResult createSuccess(Object data) {
        return new JsonResult(true, "OK", data,PetConstant.CAI_SUCCESS);
    }

    /**
     * 返回错误
     */
    public static JsonResult createError(String code, String message) {
        return new JsonResult(false, message, null, code);
    }

    /**
     * 返回错误,错误码默认系统错误
     */
    public static JsonResult createError(String message) {
        return createError(PetConstant.CAI_ERROR, message);
    }

}
